home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / GraKa / Picasso96Develop / Examples / OpenScreen.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-03  |  4.7 KB  |  173 lines

  1. /***********************************************************************
  2. * This is an example that shows how to open a p96 Screen and a Window 
  3. * to get input events and how to paint on that screen.
  4. * Program terminates when space bar or any mouse button is pressed!
  5. *
  6. * alex (Sun Dec 29 01:42:59 1996)
  7. ***********************************************************************/
  8.  
  9. #include    <proto/exec.h>
  10. #include    <proto/dos.h>
  11. #include    <proto/intuition.h>
  12. #include    <proto/timer.h>
  13. #include    <proto/graphics.h>
  14. #include    <proto/picasso96.h>
  15.  
  16. #include    <intuition/screens.h>
  17. #if defined(__GNUC__)
  18. #include    <clib/macros.h>
  19. #endif
  20.  
  21. #include    <math.h>
  22. #include    <stdio.h>
  23. #include    <stdlib.h>
  24.  
  25. char    ScreenTitle[] = "Picasso96 API Test";
  26. char    Template[] = "Width=W/N,Height=H/N,Depth=D/N";
  27. LONG    Array[] = { 0, 0, 0 };
  28. WORD    Pens[] = {~0};
  29.  
  30. struct Library    *P96Base;
  31.  
  32. struct TagItem    WindowTags[] = {
  33.     WA_Width, 200,
  34.     WA_Height, 300,
  35.     WA_MinWidth, 100,
  36.     WA_MinHeight, 100,
  37.     WA_MaxWidth, -1,
  38.     WA_MaxHeight, -1,
  39.     WA_SimpleRefresh, TRUE,
  40.     WA_RMBTrap, TRUE,
  41.     WA_Activate, TRUE,
  42.     WA_CloseGadget, TRUE,
  43.     WA_DepthGadget, TRUE,
  44.     WA_DragBar, TRUE,
  45.     WA_SizeGadget, TRUE,
  46.     WA_SizeBBottom, TRUE,
  47.     WA_GimmeZeroZero, TRUE,
  48.     WA_ScreenTitle, (ULONG)ScreenTitle,
  49.     WA_IDCMP, IDCMP_RAWKEY|IDCMP_CLOSEWINDOW,
  50.     TAG_END
  51. };
  52.  
  53. #define    random(x)    (rand()/(RAND_MAX/x))
  54.  
  55. void main(void)
  56. {
  57.     if(P96Base=OpenLibrary("Picasso96API.library",2)){
  58.         struct RDArgs    *rda;
  59.         struct Screen    *sc;
  60.  
  61.         LONG    Width = 640, Height = 480, Depth = 8;
  62.         int    i;
  63.         
  64.         if(rda = ReadArgs(Template, Array, NULL)){
  65.             if(Array[0])    Width =*((LONG *)Array[0]);
  66.             if(Array[1])    Height=*((LONG *)Array[1]);
  67.             if(Array[2])    Depth =*((LONG *)Array[2]);
  68.             FreeArgs(rda);
  69.         }
  70.  
  71.         if(sc = p96OpenScreenTags(
  72.                                         P96SA_Width, Width,
  73.                                         P96SA_Height, Height,
  74.                                         P96SA_Depth, Depth,
  75.                                         P96SA_AutoScroll, TRUE,
  76.                                         P96SA_Pens, Pens,
  77.                                         P96SA_Title, (ULONG)ScreenTitle,
  78.                                         TAG_DONE)){
  79.  
  80.             struct Window    *wdf, *wdp;
  81.             WORD    Dimensions[4];
  82.  
  83.             Dimensions[0] = 0;
  84.             Dimensions[1] = sc->BarHeight+1;
  85.             Dimensions[2] = sc->Width;
  86.             Dimensions[3] = sc->Height-sc->BarHeight-1;
  87.  
  88.             wdp = OpenWindowTags(NULL,    WA_CustomScreen, sc,
  89.                                                 WA_Title, "WritePixel",
  90.                                                 WA_Left,(sc->Width/2-200)/2 + sc->Width/2,
  91.                                                 WA_Top,(sc->Height-sc->BarHeight-300)/2,
  92.                                                 WA_Zoom, &Dimensions,
  93.                                                 TAG_MORE, WindowTags);
  94.  
  95.             wdf = OpenWindowTags(NULL,    WA_CustomScreen, sc,
  96.                                                 WA_Title, "FillRect",
  97.                                                 WA_Left,(sc->Width/2-200)/2,
  98.                                                 WA_Top,(sc->Height-sc->BarHeight-300)/2,
  99.                                                 WA_Zoom, &Dimensions,
  100.                                                 TAG_MORE, WindowTags);
  101.  
  102.             if(wdf && wdp){
  103.                 struct RastPort    *rpf = wdf->RPort;
  104.                 struct RastPort    *rpp = wdp->RPort;
  105.                 BOOL    terminate = FALSE;
  106.                 ULONG    signals = ((1<<wdf->UserPort->mp_SigBit) | (1<<wdp->UserPort->mp_SigBit));
  107.                 RGBFTYPE    format = (RGBFTYPE)p96GetBitMapAttr(sc->RastPort.BitMap, P96BMA_RGBFORMAT);
  108.  
  109.                 srand((unsigned int)wdf + (unsigned int)wdp);
  110.  
  111.                 do{
  112.                     WORD x1, y1, x2, y2, x3, y3;
  113.  
  114.                     x1 = random(wdf->Width);
  115.                     y1 = random(wdf->Height);
  116.                     x2 = random(wdf->Width);
  117.                     y2 = random(wdf->Height);
  118.                     x3 = random(wdp->Width);
  119.                     y3 = random(wdp->Height);
  120.  
  121.                     if(format == RGBFB_CLUT){
  122.                         SetAPen(rpf, random(255));
  123.                         RectFill(rpf, min(x1,x2), min(y1,y2), max(x1,x2), max(y1,y2));
  124.  
  125.                         SetAPen(rpp, random(255));
  126.                         WritePixel(rpp, x3, y3);
  127.                     }else{
  128.                         p96RectFill(rpf, min(x1,x2), min(y1,y2), max(x1,x2), max(y1,y2),
  129.                                         ((random(255))<<16)|((random(255))<<8)|(random(255)));
  130.                         p96WritePixel(rpp, x3, y3,
  131.                                         ((random(255))<<16)|((random(255))<<8)|(random(255)));
  132.                     }
  133.                     if(SetSignal(0L, signals) & signals){
  134.                         struct IntuiMessage    *imsg;
  135.  
  136.                         while(imsg=(struct IntuiMessage *)GetMsg(wdf->UserPort)){
  137.                             if((imsg->Class==IDCMP_CLOSEWINDOW) ||
  138.                                 ((imsg->Class==IDCMP_RAWKEY) && ((imsg->Code==0x40) || (imsg->Code==0x45)))){
  139.                                 // Close window, press SPACE bar or ESCAPE key to end program
  140.                                 terminate=TRUE;
  141.                             }
  142.                             ReplyMsg((struct Message *)imsg);
  143.                         }
  144.  
  145.                         while(imsg=(struct IntuiMessage *)GetMsg(wdp->UserPort)){
  146.                             if((imsg->Class==IDCMP_CLOSEWINDOW) ||
  147.                                 ((imsg->Class==IDCMP_RAWKEY) && ((imsg->Code==0x40) || (imsg->Code==0x45)))){
  148.                                 // Close window, press SPACE bar or ESCAPE key to end program
  149.                                 terminate=TRUE;
  150.                             }
  151.                             ReplyMsg((struct Message *)imsg);
  152.                         }
  153.                     }
  154.                 }while(!terminate);
  155.  
  156.                 Forbid();
  157.                 {
  158.                     struct Message    *msg;
  159.                     while(msg = GetMsg(wdf->UserPort)) ReplyMsg(msg);
  160.                     while(msg = GetMsg(wdp->UserPort)) ReplyMsg(msg);
  161.                 }
  162.                 Permit();
  163.  
  164.             }
  165.             if(wdf) CloseWindow(wdf);
  166.             if(wdp) CloseWindow(wdp);
  167.  
  168.             p96CloseScreen(sc);
  169.         }
  170.         CloseLibrary(P96Base);
  171.     }
  172. }
  173.